import {ActionContext, Module} from 'vuex';
import Ajax from '@/lib/ajax';

interface ListState {
    list: string[];
    zipFile: any;
    loading: boolean;
}

class LogModule implements Module<ListState, any> {
    namespaced = true;
    state = {
        list: new Array<string>(),
        zipFile: {},
        loading: false,
    };
    actions = {
        async getLatestWebLogs(context: ActionContext<ListState, any>, payload: any) {
            context.state.loading = true;
            const response = await Ajax.get('/api/services/app/WebLog/GetLatestWebLogs');
            context.state.loading = false;
            context.state.list = response.data.result.latestWebLogLines;
        },
        async downloadWebLogs(context: ActionContext<ListState, any>, payload: any) {
            const response = await Ajax.post('/api/services/app/WebLog/DownloadWebLogs');
            context.state.zipFile = response.data.result;
        },
    };
}

const logModule = new LogModule();
export default logModule;